{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {
        "pycharm": {}
      },
      "outputs": [],
      "source": "import pandas as pd\nimport numpy as np\nimport os\nfrom tqdm import tqdm\nimport lightgbm as lgb\nfrom sklearn.model_selection import StratifiedKFold\nfrom sklearn import metrics\nimport warnings\n\nwarnings.filterwarnings(\u0027ignore\u0027)\ntrain_path \u003d \u0027../input/hy_round1_train_20200102\u0027\ntest_path \u003d \u0027../input/hy_round1_testA_20200102\u0027"
    },
    {
      "cell_type": "code",
      "execution_count": 36,
      "metadata": {
        "pycharm": {}
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "7000 2000\n"
          ]
        }
      ],
      "source": [
        "train_files \u003d os.listdir(train_path)\n",
        "test_files \u003d os.listdir(test_path)\n",
        "print(len(train_files), len(test_files))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 11,
      "metadata": {
        "pycharm": {}
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "[\u00276966.csv\u0027, \u0027545.csv\u0027, \u0027223.csv\u0027]"
            ]
          },
          "execution_count": 11,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "train_files[:3]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 12,
      "metadata": {
        "pycharm": {}
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "[\u00278793.csv\u0027, \u00278787.csv\u0027, \u00278977.csv\u0027]"
            ]
          },
          "execution_count": 12,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "test_files[:3]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 16,
      "metadata": {
        "pycharm": {}
      },
      "outputs": [],
      "source": [
        "df \u003d pd.read_csv(f\u0027{train_path}/6966.csv\u0027)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 17,
      "metadata": {
        "pycharm": {}
      },
      "outputs": [
        {
          "data": {
            "text/html": [
              "\u003cdiv\u003e\n",
              "\u003cstyle scoped\u003e\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "\u003c/style\u003e\n",
              "\u003ctable border\u003d\"1\" class\u003d\"dataframe\"\u003e\n",
              "  \u003cthead\u003e\n",
              "    \u003ctr style\u003d\"text-align: right;\"\u003e\n",
              "      \u003cth\u003e\u003c/th\u003e\n",
              "      \u003cth\u003e渔船ID\u003c/th\u003e\n",
              "      \u003cth\u003ex\u003c/th\u003e\n",
              "      \u003cth\u003ey\u003c/th\u003e\n",
              "      \u003cth\u003e速度\u003c/th\u003e\n",
              "      \u003cth\u003e方向\u003c/th\u003e\n",
              "      \u003cth\u003etime\u003c/th\u003e\n",
              "      \u003cth\u003etype\u003c/th\u003e\n",
              "    \u003c/tr\u003e\n",
              "  \u003c/thead\u003e\n",
              "  \u003ctbody\u003e\n",
              "    \u003ctr\u003e\n",
              "      \u003cth\u003e0\u003c/th\u003e\n",
              "      \u003ctd\u003e6966\u003c/td\u003e\n",
              "      \u003ctd\u003e6.265902e+06\u003c/td\u003e\n",
              "      \u003ctd\u003e5.279254e+06\u003c/td\u003e\n",
              "      \u003ctd\u003e0.11\u003c/td\u003e\n",
              "      \u003ctd\u003e306\u003c/td\u003e\n",
              "      \u003ctd\u003e1106 23:58:16\u003c/td\u003e\n",
              "      \u003ctd\u003e围网\u003c/td\u003e\n",
              "    \u003c/tr\u003e\n",
              "    \u003ctr\u003e\n",
              "      \u003cth\u003e1\u003c/th\u003e\n",
              "      \u003ctd\u003e6966\u003c/td\u003e\n",
              "      \u003ctd\u003e6.265902e+06\u003c/td\u003e\n",
              "      \u003ctd\u003e5.279254e+06\u003c/td\u003e\n",
              "      \u003ctd\u003e0.00\u003c/td\u003e\n",
              "      \u003ctd\u003e0\u003c/td\u003e\n",
              "      \u003ctd\u003e1106 23:48:21\u003c/td\u003e\n",
              "      \u003ctd\u003e围网\u003c/td\u003e\n",
              "    \u003c/tr\u003e\n",
              "    \u003ctr\u003e\n",
              "      \u003cth\u003e2\u003c/th\u003e\n",
              "      \u003ctd\u003e6966\u003c/td\u003e\n",
              "      \u003ctd\u003e6.265902e+06\u003c/td\u003e\n",
              "      \u003ctd\u003e5.279254e+06\u003c/td\u003e\n",
              "      \u003ctd\u003e0.00\u003c/td\u003e\n",
              "      \u003ctd\u003e0\u003c/td\u003e\n",
              "      \u003ctd\u003e1106 23:38:19\u003c/td\u003e\n",
              "      \u003ctd\u003e围网\u003c/td\u003e\n",
              "    \u003c/tr\u003e\n",
              "    \u003ctr\u003e\n",
              "      \u003cth\u003e3\u003c/th\u003e\n",
              "      \u003ctd\u003e6966\u003c/td\u003e\n",
              "      \u003ctd\u003e6.265902e+06\u003c/td\u003e\n",
              "      \u003ctd\u003e5.279254e+06\u003c/td\u003e\n",
              "      \u003ctd\u003e0.00\u003c/td\u003e\n",
              "      \u003ctd\u003e0\u003c/td\u003e\n",
              "      \u003ctd\u003e1106 23:28:36\u003c/td\u003e\n",
              "      \u003ctd\u003e围网\u003c/td\u003e\n",
              "    \u003c/tr\u003e\n",
              "    \u003ctr\u003e\n",
              "      \u003cth\u003e4\u003c/th\u003e\n",
              "      \u003ctd\u003e6966\u003c/td\u003e\n",
              "      \u003ctd\u003e6.265902e+06\u003c/td\u003e\n",
              "      \u003ctd\u003e5.279254e+06\u003c/td\u003e\n",
              "      \u003ctd\u003e0.32\u003c/td\u003e\n",
              "      \u003ctd\u003e130\u003c/td\u003e\n",
              "      \u003ctd\u003e1106 23:08:17\u003c/td\u003e\n",
              "      \u003ctd\u003e围网\u003c/td\u003e\n",
              "    \u003c/tr\u003e\n",
              "  \u003c/tbody\u003e\n",
              "\u003c/table\u003e\n",
              "\u003c/div\u003e"
            ],
            "text/plain": [
              "   渔船ID             x             y    速度   方向           time type\n",
              "0  6966  6.265902e+06  5.279254e+06  0.11  306  1106 23:58:16   围网\n",
              "1  6966  6.265902e+06  5.279254e+06  0.00    0  1106 23:48:21   围网\n",
              "2  6966  6.265902e+06  5.279254e+06  0.00    0  1106 23:38:19   围网\n",
              "3  6966  6.265902e+06  5.279254e+06  0.00    0  1106 23:28:36   围网\n",
              "4  6966  6.265902e+06  5.279254e+06  0.32  130  1106 23:08:17   围网"
            ]
          },
          "execution_count": 17,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "df.head()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 18,
      "metadata": {
        "pycharm": {}
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "array([\u0027围网\u0027], dtype\u003dobject)"
            ]
          },
          "execution_count": 18,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "df[\u0027type\u0027].unique()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 19,
      "metadata": {
        "pycharm": {}
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "(389, 7)"
            ]
          },
          "execution_count": 19,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "df.shape"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 21,
      "metadata": {
        "pycharm": {}
      },
      "outputs": [
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "100%|██████████| 7000/7000 [00:34\u003c00:00, 260.00it/s]\n"
          ]
        }
      ],
      "source": [
        "ret \u003d []\n",
        "for file in tqdm(train_files):\n",
        "    df \u003d pd.read_csv(f\u0027{train_path}/{file}\u0027)\n",
        "    ret.append(df)\n",
        "df \u003d pd.concat(ret)\n",
        "df.columns \u003d [\u0027ship\u0027,\u0027x\u0027,\u0027y\u0027,\u0027v\u0027,\u0027d\u0027,\u0027time\u0027,\u0027type\u0027]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "pycharm": {}
      },
      "outputs": [],
      "source": [
        "df.to_hdf(\u0027../input/train.h5\u0027, \u0027df\u0027, mode\u003d\u0027w\u0027)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 37,
      "metadata": {
        "pycharm": {}
      },
      "outputs": [
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "100%|██████████| 2000/2000 [00:08\u003c00:00, 225.65it/s]\n"
          ]
        }
      ],
      "source": [
        "ret \u003d []\n",
        "for file in tqdm(test_files):\n",
        "    df \u003d pd.read_csv(f\u0027{test_path}/{file}\u0027)\n",
        "    ret.append(df)\n",
        "df \u003d pd.concat(ret)\n",
        "df.columns \u003d [\u0027ship\u0027,\u0027x\u0027,\u0027y\u0027,\u0027v\u0027,\u0027d\u0027,\u0027time\u0027]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 41,
      "metadata": {
        "pycharm": {}
      },
      "outputs": [],
      "source": [
        "df.to_hdf(\u0027../input/test.h5\u0027, \u0027df\u0027, mode\u003d\u0027w\u0027)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 40,
      "metadata": {
        "scrolled": true,
        "pycharm": {}
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "(782378, 6)"
            ]
          },
          "execution_count": 40,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "df.shape"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 38,
      "metadata": {
        "pycharm": {}
      },
      "outputs": [
        {
          "data": {
            "text/html": [
              "\u003cdiv\u003e\n",
              "\u003cstyle scoped\u003e\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "\u003c/style\u003e\n",
              "\u003ctable border\u003d\"1\" class\u003d\"dataframe\"\u003e\n",
              "  \u003cthead\u003e\n",
              "    \u003ctr style\u003d\"text-align: right;\"\u003e\n",
              "      \u003cth\u003e\u003c/th\u003e\n",
              "      \u003cth\u003e渔船ID\u003c/th\u003e\n",
              "      \u003cth\u003ex\u003c/th\u003e\n",
              "      \u003cth\u003ey\u003c/th\u003e\n",
              "      \u003cth\u003e速度\u003c/th\u003e\n",
              "      \u003cth\u003e方向\u003c/th\u003e\n",
              "      \u003cth\u003etime\u003c/th\u003e\n",
              "    \u003c/tr\u003e\n",
              "  \u003c/thead\u003e\n",
              "  \u003ctbody\u003e\n",
              "    \u003ctr\u003e\n",
              "      \u003cth\u003e0\u003c/th\u003e\n",
              "      \u003ctd\u003e8793\u003c/td\u003e\n",
              "      \u003ctd\u003e6.102450e+06\u003c/td\u003e\n",
              "      \u003ctd\u003e5.112760e+06\u003c/td\u003e\n",
              "      \u003ctd\u003e0.00\u003c/td\u003e\n",
              "      \u003ctd\u003e0\u003c/td\u003e\n",
              "      \u003ctd\u003e1106 23:56:34\u003c/td\u003e\n",
              "    \u003c/tr\u003e\n",
              "    \u003ctr\u003e\n",
              "      \u003cth\u003e1\u003c/th\u003e\n",
              "      \u003ctd\u003e8793\u003c/td\u003e\n",
              "      \u003ctd\u003e6.102450e+06\u003c/td\u003e\n",
              "      \u003ctd\u003e5.112760e+06\u003c/td\u003e\n",
              "      \u003ctd\u003e0.00\u003c/td\u003e\n",
              "      \u003ctd\u003e0\u003c/td\u003e\n",
              "      \u003ctd\u003e1106 23:46:34\u003c/td\u003e\n",
              "    \u003c/tr\u003e\n",
              "    \u003ctr\u003e\n",
              "      \u003cth\u003e2\u003c/th\u003e\n",
              "      \u003ctd\u003e8793\u003c/td\u003e\n",
              "      \u003ctd\u003e6.102450e+06\u003c/td\u003e\n",
              "      \u003ctd\u003e5.112760e+06\u003c/td\u003e\n",
              "      \u003ctd\u003e0.00\u003c/td\u003e\n",
              "      \u003ctd\u003e0\u003c/td\u003e\n",
              "      \u003ctd\u003e1106 23:37:31\u003c/td\u003e\n",
              "    \u003c/tr\u003e\n",
              "    \u003ctr\u003e\n",
              "      \u003cth\u003e3\u003c/th\u003e\n",
              "      \u003ctd\u003e8793\u003c/td\u003e\n",
              "      \u003ctd\u003e6.102450e+06\u003c/td\u003e\n",
              "      \u003ctd\u003e5.112760e+06\u003c/td\u003e\n",
              "      \u003ctd\u003e0.16\u003c/td\u003e\n",
              "      \u003ctd\u003e0\u003c/td\u003e\n",
              "      \u003ctd\u003e1106 23:26:34\u003c/td\u003e\n",
              "    \u003c/tr\u003e\n",
              "    \u003ctr\u003e\n",
              "      \u003cth\u003e4\u003c/th\u003e\n",
              "      \u003ctd\u003e8793\u003c/td\u003e\n",
              "      \u003ctd\u003e6.102450e+06\u003c/td\u003e\n",
              "      \u003ctd\u003e5.112760e+06\u003c/td\u003e\n",
              "      \u003ctd\u003e0.00\u003c/td\u003e\n",
              "      \u003ctd\u003e0\u003c/td\u003e\n",
              "      \u003ctd\u003e1106 23:16:34\u003c/td\u003e\n",
              "    \u003c/tr\u003e\n",
              "  \u003c/tbody\u003e\n",
              "\u003c/table\u003e\n",
              "\u003c/div\u003e"
            ],
            "text/plain": [
              "   渔船ID             x             y    速度  方向           time\n",
              "0  8793  6.102450e+06  5.112760e+06  0.00   0  1106 23:56:34\n",
              "1  8793  6.102450e+06  5.112760e+06  0.00   0  1106 23:46:34\n",
              "2  8793  6.102450e+06  5.112760e+06  0.00   0  1106 23:37:31\n",
              "3  8793  6.102450e+06  5.112760e+06  0.16   0  1106 23:26:34\n",
              "4  8793  6.102450e+06  5.112760e+06  0.00   0  1106 23:16:34"
            ]
          },
          "execution_count": 38,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "df.head()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.7.3"
    },
    "toc": {
      "base_numbering": 1,
      "nav_menu": {},
      "number_sections": true,
      "sideBar": true,
      "skip_h1_title": false,
      "title_cell": "Table of Contents",
      "title_sidebar": "Contents",
      "toc_cell": false,
      "toc_position": {},
      "toc_section_display": true,
      "toc_window_display": false
    }
  },
  "nbformat": 4,
  "nbformat_minor": 2
}